package com.nf.health.app.adapter;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.BloodoOygenBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jason on 2016/5/27.
 */
public class OxygenBooladShowAdapter extends BaseAdapter{
    ArrayList<BloodoOygenBean> newsList;
    Activity activity;
    LayoutInflater inflater = null;
    public OxygenBooladShowAdapter(Activity activity, ArrayList<BloodoOygenBean> newsList) {
        this.activity = activity;
        this.newsList = newsList;
        inflater = LayoutInflater.from(activity);
    }
    @Override
    public int getCount() {
        return newsList == null ? 0 : newsList.size();
    }

    @Override
    public Object getItem(int position) {
        if (newsList != null && newsList.size() != 0) {
            return newsList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_show_oxygen_meausre,null);
            holder.tv_measure_oxyten_item = (TextView) convertView.findViewById(R.id.tv_measure_oxyten_item);
            holder.tv_measurheasr_item = (TextView) convertView.findViewById(R.id.tv_measurheasr_item);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BloodoOygenBean model = newsList.get(position);
        holder.tv_measurheasr_item.setText(String.valueOf(model.getHeartRate()));
        holder.tv_measure_oxyten_item.setText(String.valueOf(model.getOxygenValue()));
        return convertView;
    }
    class ViewHolder {
        TextView tv_measurheasr_item;
        TextView tv_measure_oxyten_item;
    }
    /**
     * 更新适配器的方法
     *
     */
    public void updateAdapterData(ArrayList<BloodoOygenBean> list) {
        this.newsList = list;
        notifyDataSetChanged();
    }
}
